package api

import (
	"RedWork/api/middleware"
	"RedWork/api/remote"
	"RedWork/service"
	"github.com/gin-gonic/gin"
)

func API() {
	r := gin.Default()
	r.Use(middleware.Cors())
	r.Static("/image", "./templates")
	v1 := r.Group("/v1")
	rpc := r.Group("/rpc")

	rpc.POST("/user/rpcRegister", remote.RpcUserRegister())
	rpc.POST("/user/rpcLogin", remote.RpcLogin())
	rpc.POST("/user/rpcChangePw", remote.RpcChangePw())

	v1.POST("/user/userCenter/email", EmailRegister()) //邮箱注册
	v1.GET("/user/userCenter/email/verify", EmailVerify())

	v1.POST("/user/userCenter", Userregiser())                       //注册
	v1.POST("/user/login", UserLogin())                              //登录
	v1.POST("/user/loginout", Userloginout())                        //登出
	v1.POST("/user/recharge", service.MiddlewareJWT(), Recharge())   //充值
	v1.GET("/user/detail", service.MiddlewareJWT(), QueryUserInfo()) //查询用户信息

	v1.GET("/home/allgoods/:page", HomeGetAllGoods()) //获取主要商品
	v1.GET("/home/goods", SearchGoods())              //搜索商品
	v1.GET("/home/category/code", GetCategory())      //获取商品目录代码
	v1.GET("/home/category", GetCategoryGoods())      //获取商品目录

	v1.GET("/phone/getsort", GetPhoneSort()) //获取分类信息
	v1.GET("/phone", GetSort())              //查询分类信息

	v1.GET("/store/allgoods", GetStoreGood()) //获取商城信息

	v1.GET("/phone/detail", GetDetail()) //获取手机细节

	v1.POST("/good/car", service.MiddlewareJWT(), AddCar())        //添加购物车
	v1.GET("/good/car", service.MiddlewareJWT(), QueryCar())       //查询用户购物车
	v1.DELETE("/good/car", service.MiddlewareJWT(), DeleteCar())   //删除购物车
	v1.PUT("/good/car", service.MiddlewareJWT(), UpdateCar())      //更新购物车
	v1.PUT("/good/car/clean", service.MiddlewareJWT(), CleanCar()) //一键清空购物车

	v1.POST("/good/comment", service.MiddlewareJWT(), AddComment())  //添加评论
	v1.GET("/good/comment", service.MiddlewareJWT(), QueryComment()) //请求评论

	v1.POST("/good/focus", service.MiddlewareJWT(), AddFocus())       //添加关注
	v1.GET("/good/focus", service.MiddlewareJWT(), QueryFocusGood())  //请求关注信息
	v1.PUT("/good/focus", service.MiddlewareJWT(), DeleteFocusGood()) //删除关注

	v1.POST("/order", service.MiddlewareJWT(), AddOrder())         //添加订单
	v1.GET("/order/detail", service.MiddlewareJWT(), QueryOrder()) //请求订单单一信息
	v1.GET("/order", service.MiddlewareJWT(), QueryUserOrder())    //请求用户所有订单
	v1.PUT("/order", service.MiddlewareJWT(), CancelOrder())       //删除订单
	v1.POST("/order/pay", service.MiddlewareJWT(), PayOrder())     //支付订单

	v1.GET("/store/head", GetStoreHead()) //

	r.Run(":8081")
}
